﻿<UserControl x:Class="VrPlayer.Views.Menu"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:converters="clr-namespace:VrPlayer.Helpers.Converters;assembly=VrPlayer.Helpers"
             xmlns:System="clr-namespace:System;assembly=mscorlib"
             xmlns:local="clr-namespace:VrPlayer.Contracts.Projections;assembly=VrPlayer.Contracts"
             xmlns:state="clr-namespace:VrPlayer.Models.State"
             mc:Ignorable="d">
    <UserControl.Resources>
        <converters:CompareAllParametersConverter x:Key="CompareAllParameters"/>
        <converters:CanExecuteToVisibilityConverter x:Key="CanExecuteToVisibility"/>
        <converters:PathToFileInfosConverter x:Key="PathToFileInfos"/>
        <converters:NotZeroConverter x:Key="NotZero"/>
        <converters:TranslationConverter x:Key="Translation"/>
        <ObjectDataProvider x:Key="FormatsEnum" MethodName="GetValues" ObjectType="{x:Type System:Enum}">
            <ObjectDataProvider.MethodParameters>
                <x:Type TypeName="local:StereoMode"/>
            </ObjectDataProvider.MethodParameters>
        </ObjectDataProvider>
        <ObjectDataProvider x:Key="LayoutsEnum" MethodName="GetValues" ObjectType="{x:Type System:Enum}">
            <ObjectDataProvider.MethodParameters>
                <x:Type TypeName="state:LayoutMode"/>
            </ObjectDataProvider.MethodParameters>
        </ObjectDataProvider>
        <Style TargetType="Image">
            <Setter Property="Width" Value="16" />
            <Setter Property="Height" Value="16" />
            <Setter Property="VerticalAlignment" Value="Center" />
            <Setter Property="HorizontalAlignment" Value="Center" />
        </Style>
    </UserControl.Resources>
    <Menu>
        <MenuItem Header="_File">
            <!--Open File-->
            <MenuItem Header="_Open File" ItemsSource="{Binding Path=PluginManager.Medias}" IsEnabled="{Binding Path=CanOpenFile}">
                <MenuItem.Icon>
                    <Image Source="/Medias/Nuvola/16x16/fileopen.png" />
                </MenuItem.Icon>
                <MenuItem.ItemContainerStyle>
                    <Style TargetType="{x:Type MenuItem}">
                        <Setter Property="Visibility" Value="{Binding Path=Content.OpenFileCommand, Converter={StaticResource CanExecuteToVisibility}}"/>
                        <Setter Property="Header" Value="{Binding Path=Name}" />
                        <Setter Property="HeaderStringFormat" Value="with {0}..." />
                        <Setter Property="Command">
                            <Setter.Value>
                                <Binding RelativeSource="{RelativeSource FindAncestor, AncestorType={x:Type UserControl}}" Path="DataContext.OpenFileCommand" />
                            </Setter.Value>
                        </Setter>
                        <Setter Property="CommandParameter" Value="{Binding Path=.}" />
                    </Style>
                </MenuItem.ItemContainerStyle>
            </MenuItem>
            <!--Open Stream-->
            <MenuItem Header="Open _Stream" ItemsSource="{Binding Path=PluginManager.Medias}" IsEnabled="{Binding Path=CanOpenStream}">
                <MenuItem.Icon>
                    <Image Source="/Medias/Nuvola/16x16/browser.png" />
                </MenuItem.Icon>
                <MenuItem.ItemContainerStyle>
                    <Style TargetType="{x:Type MenuItem}">
                        <Setter Property="Visibility" Value="{Binding Path=Content.OpenStreamCommand, Converter={StaticResource CanExecuteToVisibility}}"/>
                        <Setter Property="Header" Value="{Binding Path=Name}" />
                        <Setter Property="HeaderStringFormat" Value="with {0}..." />
                        <Setter Property="Command">
                            <Setter.Value>
                                <Binding RelativeSource="{RelativeSource FindAncestor, AncestorType={x:Type UserControl}}" Path="DataContext.OpenStreamCommand" />
                            </Setter.Value>
                        </Setter>
                        <Setter Property="CommandParameter" Value="{Binding Path=.}" />
                    </Style>
                </MenuItem.ItemContainerStyle>
            </MenuItem>
            <!--Open Disc-->
            <MenuItem Header="Open _Disc" ItemsSource="{Binding Path=PluginManager.Medias}" IsEnabled="{Binding Path=CanOpenDisc}">
                <MenuItem.Icon>
                    <Image Source="/Medias/Nuvola/16x16/cd.png" />
                </MenuItem.Icon>
                <MenuItem.ItemContainerStyle>
                    <Style TargetType="{x:Type MenuItem}">
                        <Setter Property="Visibility" Value="{Binding Path=Content.OpenDiscCommand, Converter={StaticResource CanExecuteToVisibility}}"/>
                        <Setter Property="Header" Value="{Binding Path=Name}" />
                        <Setter Property="HeaderStringFormat" Value="with {0}..." />
                        <Setter Property="Command">
                            <Setter.Value>
                                <Binding RelativeSource="{RelativeSource FindAncestor, AncestorType={x:Type UserControl}}" Path="DataContext.OpenDiscCommand" />
                            </Setter.Value>
                        </Setter>
                        <Setter Property="CommandParameter" Value="{Binding Path=.}" />
                    </Style>
                </MenuItem.ItemContainerStyle>
            </MenuItem>
            <!--Open Device-->
            <MenuItem Header="Open _Capture device" ItemsSource="{Binding Path=PluginManager.Medias}" IsEnabled="{Binding Path=CanOpenDevice}" Visibility="Collapsed">
                <MenuItem.Icon>
                    <Image Source="/Medias/Nuvola/16x16/kcmpci.png" />
                </MenuItem.Icon>
                <MenuItem.ItemContainerStyle>
                    <Style TargetType="{x:Type MenuItem}">
                        <Setter Property="Visibility" Value="{Binding Path=Content.OpenDeviceCommand, Converter={StaticResource CanExecuteToVisibility}}"/>
                        <Setter Property="Header" Value="{Binding Path=Name}" />
                        <Setter Property="HeaderStringFormat" Value="with {0}..." />
                        <Setter Property="Command">
                            <Setter.Value>
                                <Binding RelativeSource="{RelativeSource FindAncestor, AncestorType={x:Type UserControl}}" Path="DataContext.OpenDeviceCommand" />
                            </Setter.Value>
                        </Setter>
                        <Setter Property="CommandParameter" Value="{Binding Path=.}" />
                    </Style>
                </MenuItem.ItemContainerStyle>
            </MenuItem>
            <!--Open Process-->
            <MenuItem Header="Open _Process" ItemsSource="{Binding Path=PluginManager.Medias}" IsEnabled="{Binding Path=CanOpenProcess}">
                <MenuItem.Icon>
                    <Image Source="/Medias/Nuvola/16x16/window_list.png" />
                </MenuItem.Icon>
                <MenuItem.ItemContainerStyle>
                    <Style TargetType="{x:Type MenuItem}">
                        <Setter Property="Visibility" Value="{Binding Path=Content.OpenProcessCommand, Converter={StaticResource CanExecuteToVisibility}}"/>
                        <Setter Property="Header" Value="{Binding Path=Name}" /> 
                        <Setter Property="HeaderStringFormat" Value="with {0}..." />
                        <Setter Property="Command">
                            <Setter.Value>
                                <Binding RelativeSource="{RelativeSource FindAncestor, AncestorType={x:Type UserControl}}" Path="DataContext.OpenProcessCommand" />
                            </Setter.Value>
                        </Setter>
                        <Setter Property="CommandParameter" Value="{Binding Path=.}" />
                    </Style>
                </MenuItem.ItemContainerStyle>
            </MenuItem>
            <Separator />
            <!--Samples-->
            <MenuItem Header="_Samples" ItemsSource="{Binding Path=Config.SamplesFolder, Converter={StaticResource PathToFileInfos}}">
				<MenuItem.Icon>
					<Image Source="/Medias/Nuvola/16x16/edu_science.png" />
				</MenuItem.Icon>
                <MenuItem.ItemContainerStyle>
                    <Style TargetType="{x:Type MenuItem}">
                        <Setter Property="Header" Value="{Binding Path=Name}" />
                        <Setter Property="Command">
                            <Setter.Value>
                                <Binding RelativeSource="{RelativeSource FindAncestor, AncestorType={x:Type UserControl}}" Path="DataContext.OpenCommand" />
                            </Setter.Value>
                        </Setter>
                        <Setter Property="CommandParameter" Value="{Binding Path=FullName}" />
                    </Style>
                </MenuItem.ItemContainerStyle>
            </MenuItem>
            <MenuItem Header="_Browse Samples..." Command="{Binding BrowseSamplesCommand}">				
                <MenuItem.Icon>
                    <Image Source="/Medias/Nuvola/16x16/folder_open.png" />
				</MenuItem.Icon>
            </MenuItem>
            <Separator />
            <MenuItem Header="E_xit" Command="{Binding ExitCommand}">
                <MenuItem.Icon>
                    <Image Source="/Medias/Nuvola/16x16/exit.png" />
                </MenuItem.Icon>
            </MenuItem>
        </MenuItem>
        <MenuItem Header="_Media">
            <!--Format-->
            <MenuItem Header="_Format" ItemsSource="{Binding Source={StaticResource FormatsEnum}}">
                <MenuItem.Icon>
                    <Image Source="/Medias/Nuvola/16x16/edit.png" />
                </MenuItem.Icon>
                <MenuItem.ItemContainerStyle>
                    <Style TargetType="{x:Type MenuItem}">
                        <Setter Property="Header">
                            <Setter.Value>
                                <Binding Path="." Converter="{StaticResource Translation}"></Binding>
                            </Setter.Value>
                        </Setter>
                        <Setter Property="IsChecked">
                            <Setter.Value>
                                <MultiBinding Converter="{StaticResource CompareAllParameters}" ConverterParameter="String">
                                    <Binding Path="." />
                                    <Binding RelativeSource="{RelativeSource FindAncestor, AncestorType={x:Type UserControl}}" Path="DataContext.State.StereoInput" />
                                </MultiBinding>
                            </Setter.Value>
                        </Setter>
                        <Setter Property="Command">
                            <Setter.Value>
                                <Binding RelativeSource="{RelativeSource FindAncestor, AncestorType={x:Type UserControl}}" Path="DataContext.ChangeFormatCommand" />
                            </Setter.Value>
                        </Setter>
                        <Setter Property="CommandParameter" Value="{Binding Path=.}" />
                    </Style>
                </MenuItem.ItemContainerStyle>
            </MenuItem>
            <!--Projections-->
            <MenuItem Header="_Projection" ItemsSource="{Binding Path=PluginManager.Projections}" IsEnabled="{Binding Path=PluginManager.Projections.Count, Converter={StaticResource NotZero}}">
                <MenuItem.Icon>
                    <Image Source="/Medias/Nuvola/16x16/kpovmodeler.png" />
                </MenuItem.Icon>
                <MenuItem.ItemContainerStyle>
                    <Style TargetType="{x:Type MenuItem}">
                        <Setter Property="Header" Value="{Binding Path=Name}" />
                        <Setter Property="IsChecked">
                            <Setter.Value>
                                <MultiBinding Converter="{StaticResource CompareAllParameters}">
                                    <Binding Path="." />
                                    <Binding RelativeSource="{RelativeSource FindAncestor, AncestorType={x:Type UserControl}}" Path="DataContext.State.ProjectionPlugin" /> 
                                </MultiBinding>
                            </Setter.Value>
                        </Setter>
                        <Setter Property="Command">
                            <Setter.Value>
                                <Binding RelativeSource="{RelativeSource FindAncestor, AncestorType={x:Type UserControl}}" Path="DataContext.ChangeProjectionCommand" />
                            </Setter.Value>
                        </Setter>
                        <Setter Property="CommandParameter" Value="{Binding Path=.}" />
                    </Style>
                </MenuItem.ItemContainerStyle>
            </MenuItem>
            <!--Effects-->
            <MenuItem Header="_Effects" ItemsSource="{Binding Path=PluginManager.Effects}" IsEnabled="{Binding Path=PluginManager.Effects.Count, Converter={StaticResource NotZero}}">
                <MenuItem.Icon>
                    <Image Source="/Medias/Nuvola/16x16/package_graphics.png" />
                </MenuItem.Icon>
                <MenuItem.ItemContainerStyle>
                    <Style TargetType="{x:Type MenuItem}">
                        <Setter Property="Header" Value="{Binding Path=Name}" />
                        <Setter Property="IsChecked">
                            <Setter.Value>
                                <MultiBinding Converter="{StaticResource CompareAllParameters}">
                                    <Binding Path="." />
                                    <Binding RelativeSource="{RelativeSource FindAncestor, AncestorType={x:Type UserControl}}" Path="DataContext.State.EffectPlugin" />
                                </MultiBinding>
                            </Setter.Value>
                        </Setter>
                        <Setter Property="Command">
                            <Setter.Value>
                                <Binding RelativeSource="{RelativeSource FindAncestor, AncestorType={x:Type UserControl}}" Path="DataContext.ChangeEffectCommand" />
                            </Setter.Value>
                        </Setter>
                        <Setter Property="CommandParameter" Value="{Binding Path=.}" />
                    </Style>
                </MenuItem.ItemContainerStyle>
            </MenuItem>
        </MenuItem>
        <MenuItem Header="_Device">
            <!--Layout-->
            <MenuItem Header="_Layout" ItemsSource="{Binding Source={StaticResource LayoutsEnum}}">
                <MenuItem.Icon>
                    <Image Source="/Medias/Nuvola/16x16/view_left_right.png" />
                </MenuItem.Icon>
                <MenuItem.ItemContainerStyle>
                    <Style TargetType="{x:Type MenuItem}">
                        <Style.Triggers>
                            <DataTrigger Value="{x:Static state:LayoutMode.DualScreen}" Binding="{Binding Path=.}">
                                <Setter Property="IsEnabled">
                                    <Setter.Value>
                                        <Binding RelativeSource="{RelativeSource FindAncestor, AncestorType={x:Type UserControl}}" Path="DataContext.SupportDualScreen" />
                                    </Setter.Value>
                                </Setter>
                            </DataTrigger>
                        </Style.Triggers>
                        <Setter Property="Header">
                            <Setter.Value>
                                <Binding Path="." Converter="{StaticResource Translation}"></Binding>
                            </Setter.Value>
                        </Setter>
                        <Setter Property="IsChecked">
                            <Setter.Value>
                                <MultiBinding Converter="{StaticResource CompareAllParameters}" ConverterParameter="String">
                                    <Binding Path="." />
                                    <Binding RelativeSource="{RelativeSource FindAncestor, AncestorType={x:Type UserControl}}" Path="DataContext.State.StereoOutput" />
                                </MultiBinding>
                            </Setter.Value>
                        </Setter>
                        <Setter Property="Command">
                            <Setter.Value>
                                <Binding RelativeSource="{RelativeSource FindAncestor, AncestorType={x:Type UserControl}}" Path="DataContext.ChangeLayoutCommand" />
                            </Setter.Value>
                        </Setter>
                        <Setter Property="CommandParameter" Value="{Binding Path=.}" />
                    </Style>
                </MenuItem.ItemContainerStyle>
            </MenuItem>
            <!--Distortions-->
            <MenuItem Header="_Distortion" ItemsSource="{Binding Path=PluginManager.Distortions}" IsEnabled="{Binding Path=PluginManager.Distortions.Count, Converter={StaticResource NotZero}}">
                <MenuItem.Icon>
                    <Image Source="/Medias/Nuvola/16x16/xmag.png" />
                </MenuItem.Icon>
                <MenuItem.ItemContainerStyle>
                    <Style TargetType="{x:Type MenuItem}">
                        <Setter Property="Header" Value="{Binding Path=Name}" />
                        <Setter Property="IsChecked">
                            <Setter.Value>
                                <MultiBinding Converter="{StaticResource CompareAllParameters}">
                                    <Binding Path="." />
                                    <Binding RelativeSource="{RelativeSource FindAncestor, AncestorType={x:Type UserControl}}" Path="DataContext.State.DistortionPlugin" />
                                </MultiBinding>
                            </Setter.Value>
                        </Setter>
                        <Setter Property="Command">
                            <Setter.Value>
                                <Binding RelativeSource="{RelativeSource FindAncestor, AncestorType={x:Type UserControl}}" Path="DataContext.ChangeDistortionCommand" />
                            </Setter.Value>
                        </Setter>
                        <Setter Property="CommandParameter" Value="{Binding Path=.}" />
                    </Style>
                </MenuItem.ItemContainerStyle>
            </MenuItem>
            <!--Trackers-->
            <MenuItem Header="Trac_ker" ItemsSource="{Binding Path=PluginManager.Trackers}" IsEnabled="{Binding Path=PluginManager.Trackers.Count, Converter={StaticResource NotZero}}">
                <MenuItem.Icon>
                    <Image Source="/Medias/Nuvola/16x16/package_games_arcade.png" />
                </MenuItem.Icon>
                <MenuItem.ItemContainerStyle>
                    <Style TargetType="{x:Type MenuItem}">
                        <Setter Property="Header" Value="{Binding Path=Name}" />
                        <!--Setter Property="IsEnabled" Value="{Binding Path=Content.IsEnabled}" /-->
                        <Setter Property="IsChecked">
                            <Setter.Value>
                                <MultiBinding Converter="{StaticResource CompareAllParameters}">
                                    <Binding Path="." />
                                    <Binding RelativeSource="{RelativeSource FindAncestor, AncestorType={x:Type UserControl}}" Path="DataContext.State.TrackerPlugin" />
                                </MultiBinding>
                            </Setter.Value>
                        </Setter>
                        <Setter Property="Command">
                            <Setter.Value>
                                <Binding RelativeSource="{RelativeSource FindAncestor, AncestorType={x:Type UserControl}}" Path="DataContext.ChangeTrackerCommand" />
                            </Setter.Value>
                        </Setter>
                        <Setter Property="CommandParameter" Value="{Binding Path=.}" />
                    </Style>
                </MenuItem.ItemContainerStyle>
            </MenuItem>
        </MenuItem>
        <MenuItem Header="_Tools">
            <!-- Presets -->
            <MenuItem Header="_Save Preset">
                <MenuItem.Icon>
                    <Image Source="/Medias/Nuvola/16x16/cache.png" />
                </MenuItem.Icon>
                <MenuItem Header="Media..." Click="SaveMediaPresetMenuItem_OnClick"></MenuItem>
                <MenuItem Header="Device..." Click="SaveDevicePresetMenuItem_OnClick"></MenuItem>
                <Separator />
                <MenuItem Header="All..." Click="SaveAllPresetMenuItem_OnClick"></MenuItem>
            </MenuItem>
            <MenuItem Header="_Load Preset">
                <MenuItem.Icon>
                    <Image Source="/Medias/Nuvola/16x16/kdisknav.png" />
                </MenuItem.Icon>
                <MenuItem Header="From file..." Click="LoadPresetMenuItem_OnClick"></MenuItem>
                <MenuItem Header="From metadata" Click="LoadMetadataPresetMenuItem_OnClick"></MenuItem>
                <Separator />
                <MenuItem Header="Reset default" Command="{Binding ResetPresetCommand}"></MenuItem>
            </MenuItem>
            <Separator />
            <MenuItem Header="_Settings..." Command="{Binding SettingsCommand}" CommandParameter="0">
                <MenuItem.Icon>
                    <Image Source="/Medias/Nuvola/16x16/kservices.png" />
                </MenuItem.Icon>
            </MenuItem>
      </MenuItem>
        <MenuItem Header="_?">
            <MenuItem Header="_Visit vrplayer.tv..." Command="{Binding LaunchWebBrowserCommand}">
                <MenuItem.Icon>
                    <Image Source="../vrplayer.ico" />
                </MenuItem.Icon>
            </MenuItem>
            <Separator />
            <MenuItem Header="_About..." Command="{Binding AboutCommand}">
                <MenuItem.Icon>
                    <Image Source="/Medias/Nuvola/16x16/help.png" />
                </MenuItem.Icon>
            </MenuItem>
        </MenuItem>
    </Menu>
</UserControl>
